package cn.meetingroom.service;

import cn.meetingroom.dao.NoticeDao;
import cn.meetingroom.dao.UserDao;
import cn.meetingroom.model.Notice;

import java.sql.Timestamp;
import java.util.List;

public class NoticeService {
    private NoticeDao noticeDao = new NoticeDao();
    private UserDao userDao = new UserDao();

    public boolean addNotice(Notice notice){
        if (noticeDao.addNotice(notice)) return true;
        return false;
    }

    public List<Notice> getNoticeList(){
        return noticeDao.getAllNotice();
    }

    public boolean delNotice(String colName,Object value){
        return noticeDao.delNotice(colName,value);
    }

    public int getUnreadNum(long id){
        UserDao userDao = new UserDao();
        Timestamp t = userDao.getUnreadTime(id);
        if (t != null){
            return noticeDao.getUnreadNum(t);
        } else {
            return noticeDao.getAllNotice().size();
        }
    }

    public boolean upReadTime(long id){
        if (userDao.updateReadTime(id)) return true;
        return false;
    }
}
